Skip to content

Improve URLSearchParams constructor type definition #2070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rossrobino
Copy link

@rossrobino rossrobino commented Jul 16, 2025

Overrides the type of URLSearchParams init to accept a Iterable<[string, string]> instead of string[][].

MDN Reference

For example:

new URLSearchParams(new Set([["name", "ross"]]));

is valid, but currently shows an error.

There was an added type of URLSearchParams which I figured I should remove, the Iterable<[string, string]> type covers this case as well.

@rossrobino
Copy link
Author

@microsoft-github-policy-service agree

Copy link
Contributor

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

@jakebailey
Copy link
Member

I can't seem to get it to generate, I'm getting a ENOENT error. I don't have files in /inputfiles/mdn/

You need to have cloned the submodule as well.

git submodule update --init

@saschanaz
Copy link
Contributor

This is blocked by #222 because vars can't be split by separate type declarations. We cannot just override the constructor because it'll break ES5 compatibility.

microsoft/TypeScript#3538 could greatly help without all those separate libs but I don't see that coming anytime soon.

@jakebailey
Copy link
Member

ES5 is going to be deprecated, so maybe there's a future where it'd work out.

@rossrobino
Copy link
Author

Thanks @jakebailey, got it to generate and committed the changes.

I am seeing the Cannot find name 'Iterable' error now during the test run, I assume this is the ES5 issue. Let me know if not!

@jakebailey
Copy link
Member

Correct, but we're likely making DOM imply ES6 and DOM.Iterable in 6.0

@saschanaz
Copy link
Contributor

But will 6.0 remove ES5 completely?

@jakebailey
Copy link
Member

As a target for emit, yes, at least deprecated.

The rest is more a product of us wanting to make DOM.Iterable auto included, but that means we need Symbol, which means ES6, or at least the es6 symbol libs. It isn't really clean to do, so still figuring it out.

@jakebailey
Copy link
Member

Actually, why isn't this being stuck into the iterable d.ts file?

@rossrobino
Copy link
Author

I can add or feel free to edit as well! I'm not sure exactly which file you are referencing. Should it be added to the generated file here as the call signature? https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/main/baselines/dom.iterable.generated.d.ts#L400

@saschanaz
Copy link
Contributor

Actually, why isn't this being stuck into the iterable d.ts file?

Because we can't override constructors without having #222 first.

@jakebailey
Copy link
Member

For 6.0, we're going to make the DOM types reference ES6/ES2015 (and promote DOM.Iterable to just being DOM), so we could probably just wait a bit and this will all be a non-issue.

Though, why isn't this a Constructor type instead of a named interface that can be merged into, like we do Map and such?

@saschanaz
Copy link
Contributor

You mean defining a separate interface? Because that'll pollute the global namespace 2x than we do now...

@jakebailey
Copy link
Member

Yes, since that's what we do in the main libs, but I suppose that would be pretty noisy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants